SwapIt / app / api / product / [pid] / description / route.js
route.js
Raw
import { op } from "@utils/user.mjs";

export const GET = async ( req, {params}) => {
    try {
        const Product = await op.findProductById(params.pid);
        const User = await op.findUserById(Product.data[1]);
        const data= {
            Product : Product.data,
            User: User.data,
        }


        if(!Product.found) return new Response("Product not found", {status: 204} )
        if(!User.found) return new Response("User not found", {status: 204} )
        
        return new Response( JSON.stringify(data) , {status:200})
        
    } catch (error) {
        return new Response("Failed to read the Product Or User" , {status:500});
    }
}